import axios from 'axios'
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
let zhuzhu = {
  state: {
    // 请求返回的数据
    topics: []
  },
  mutations: {
    gettopics(state, val) {
      state.topics = val.data.data
    }
  },
  actions: {
    axiostopics({
      commit
    }, val) {
      return axios({
        url: 'https://cnodejs.org/api/v1/topics',
        method: 'get',
        params: {
          tab: val,
        }
      }).then((res) => {
        commit('gettopics', res)
        return res;
      })
    }
  },
}
let dh = {
  state: {
    // 详细页的信息
    d_lists: []
  },
  mutations: {
    de_list(contxt, res1) {
      contxt.d_lists = res1
    }
  },
  actions: {
    detailed_list(contxt, objed) {
      console.log(objed);
      if (objed.ac != false) {

        axios.get("https://cnodejs.org/api/v1/topic/" + objed.gid, {
          accesstoken: objed.ac
        }).then(res => {
          contxt.commit("de_list", res.data.data)
        })
      } else {
        console.log(objed);
        axios.get("https://cnodejs.org/api/v1/topic/" + objed.gid).then(res => {
          contxt.commit("de_list", res.data.data)
        })
      }
    }
  },
}
export default new Vuex.Store({
  state: {},
  mutations: {},
  actions: {},
  modules: {
    dh,
    zhuzhu
  }
})